package com.spic.business.report.controller;

import com.fasterxml.jackson.annotation.JsonView;
import com.spic.business.report.dto.QueryForm;
import com.spic.business.report.dto.ScreenDto;
import com.spic.business.report.dto.ScreenForm;
import com.spic.business.report.service.ScreenService;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@AllArgsConstructor
@RequestMapping("/screen")
public class ScreenController extends BaseController
{

    private final ScreenService screenService;

    @GetMapping("/list")
    @JsonView(ScreenDto.ScreenListView.class)
    public AjaxResult screenInfoList(@Validated QueryForm form) {

        return AjaxResult.success(screenService.getScreenInfoList(form));
    }

    @GetMapping("/{id}")
    public ScreenDto screenInfo(@PathVariable("id") String screenId) {
        return this.screenService.getScreenInfo(screenId);
    }

    @PostMapping("/save")
    public AjaxResult saveScreenInfo(@RequestBody @Validated ScreenForm form) {
        this.screenService.saveScreenInfo(form);
        return AjaxResult.success();
    }

    @PostMapping("/status")
    public AjaxResult changeScreenStatus(@RequestParam("id") String screenId) {
        this.screenService.changeScreenStatus(screenId);
        return AjaxResult.success();
    }
    @DeleteMapping("/delete/{id}")
    public AjaxResult deleteScreenInfo(@PathVariable("id") String screenId) {
        this.screenService.deleteScreenInfo(screenId);
        return AjaxResult.success();
    }
}
